/* PutDataDirect FinalData Macro */

/*
** $ver: 1.0 copyright 1994 by Merrill Callaway
** All rights reserved worldwide
**
** Puts data directly into cells from ascii
** database file.
*/

signal on Break_C
options results
file=getclip('FDASCIIFILE')
rc=open('in',file,r)
colhead=readln('in')

tab="9"x

portname
port=result
address value port

/* make small window to speed things up */
getwindowinfo
win=result
parse var win . . w h mw mh .
'sizewindow' mw mh

selectrow 1
cut force

/* count columns */
do cols=1 while colhead~=''
   parse var colhead . (tab) colhead
end
cols=cols-1

do i=1 while ~eof('in')
   line.i=readln('in')
   if line.i = '' then do
      nextcell
      leave
   end
   newrow
   do j=1 to cols

      parse var line.i col.j (tab) line.i

      /* handle raw vs. formatted data */
      /* you may need additional code here! */
      if left(col.j,1)='$' then do
         col.j=strip(col.j,'L','$')
         num=''
         do while col.j ~=''
            parse var col.j first ',' col.j
            num=num||first
         end
         col.j=num
      end

      if col.j='' then col.j = ' '
      cmd='insert '||col.j
      cmd
      if j<cols then nextcell
   end
end
/* make window big again */
'sizewindow' w h

'showmessage 1 1',
 '"Do you wish to save new database?"',
  '"ASCII database file is in"' file,
   '"Save" "Cancel" ""'
if result=1 then saveas

Break_C:

call close('in')
call setclip('FDASCIIFILE')

exit